# Makefile for Ingenic Video Streamer (Linux)
# 君正视频推流项目 - Linux版本

# 编译器设置
CXX = g++
CXXFLAGS = -std=c++17 -O2 -Wall -Wextra -pthread

# 项目名称
TARGET = IngenicVideoStreamer

# 源文件
SOURCES = main.cpp \
          IngenicVideoSource.cpp \
          IngenicEncoder.cpp

# 头文件
HEADERS = IngenicVideoSource.h \
          IngenicEncoder.h

# 目标文件
OBJECTS = $(SOURCES:.cpp=.o)

# 君正SDK路径（需要根据实际安装路径调整）
INGENIC_SDK_PATH = ../Ingenic_SDK
INGENIC_INCLUDE = $(INGENIC_SDK_PATH)
INGENIC_LIB = $(INGENIC_SDK_PATH)/libimp.a

# live555路径（需要根据实际安装路径调整）
LIVE555_PATH = ../live555
LIVE555_INCLUDE = $(LIVE555_PATH)/include
LIVE555_LIB = $(LIVE555_PATH)/lib

# 包含路径
INCLUDES = -I. \
           -I$(INGENIC_INCLUDE) \
           -I$(LIVE555_INCLUDE)

# 库路径
LIB_PATHS = -L$(LIVE555_LIB)

# 链接库
LIBS = -lliveMedia \
       -lgroupsock \
       -lBasicUsageEnvironment \
       -lUsageEnvironment \
       -lpthread \
       -lrt \
       -ldl \
       -lm

# 君正SDK库
INGENIC_LIBS = $(INGENIC_LIB)

# 默认目标
all: $(TARGET)

# 链接目标
$(TARGET): $(OBJECTS)
	$(CXX) $(CXXFLAGS) -o $@ $^ $(LIB_PATHS) $(LIBS) $(INGENIC_LIBS)

# 编译规则
%.o: %.cpp $(HEADERS)
	$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@

# 清理
clean:
	rm -f $(OBJECTS) $(TARGET)

# 安装（可选）
install: $(TARGET)
	cp $(TARGET) /usr/local/bin/

# 卸载（可选）
uninstall:
	rm -f /usr/local/bin/$(TARGET)

# 帮助
help:
	@echo "可用的目标:"
	@echo "  all      - 编译项目"
	@echo "  clean    - 清理编译文件"
	@echo "  install  - 安装到系统"
	@echo "  uninstall- 从系统卸载"
	@echo "  help     - 显示此帮助信息"

# 依赖关系
main.o: main.cpp IngenicVideoSource.h
IngenicVideoSource.o: IngenicVideoSource.cpp IngenicVideoSource.h IngenicEncoder.h
IngenicEncoder.o: IngenicEncoder.cpp IngenicEncoder.h

.PHONY: all clean install uninstall help
